﻿var prizeJson;
var mouldJson;
var EventJson;
var mouldConditionJson;
var TaskTypeJsons;
var pageSize = 15;
var isReachCondition = ""; //是否达到条件即可获取奖false：调用道具为条件 true：调用可为条件任务的事件及概率模板
var isMouldOrEvent = ""; //true：chancemould的值  false：event的值

$(document).ready(function () {
    $("#txtTaskName").focus(function () {
        if ($(this).val() == "输入任务名称查询") {
            $(this).val("");
        }
    });
    $("#txtTaskName").blur(function () {
        if ($(this).val() == "") {
            $(this).val($(this).attr("default"));
        }

    });
    PageClickFunc(1);
    $("#btnSele").click(function () {
        InitTaskList(1)
    });
    //GetPrizeAndConditionList(id, name, isReachCondition);
    $.ajax({
        type: "post",
        data: { action: "GetListByIsTaskCondition" },
        dataType: "json",
        url: "../../Ajax/PrizeAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                prizeJson = data.json;
            }
        },
        complete: function () {
        },
        error: function () {
        }
    });

    $.ajax({
        type: "post",
        data: { action: "GetTaskCondition" },
        dataType: "json",
        url: "../../Ajax/ChanceMouldAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                mouldJson = data.json;
            }
        },
        complete: function () {
        },
        error: function () {
        }
    });

    $.ajax({
        type: "post",
        data: { action: "GetTaskCondition" },
        dataType: "json",
        url: "../../Ajax/EventAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                EventJson = data.json;
            }
        },
        complete: function () {
        },
        error: function () {
        }
    });

    $.ajax({
        type: "post",
        data: { action: "GetConditionMould" },
        dataType: "json",
        url: "../../Ajax/TaskConditionAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                mouldConditionJson = data.json;
            }
        },
        complete: function () {
        },
        error: function () {
        }
    });

    $("#btnCondition").click(function () {
        Edit(null);
    })


    $("#btnAddPrize").click(function () {
        EditPrize(null);
    })
})
PageClickFunc = function (pageclickednumber) {
    InitTaskList(pageclickednumber);
}
function InitTaskList(pageclickednumber) {
    $.ajax({
        type: "post",
        data: { action: "GetListByTaskTypeID", typeID: 0, pageIndex: pageclickednumber, pageSize: pageSize, taskName: $("#txtTaskName").val() == "输入任务名称查询" ? "" : $("#txtTaskName").val() },
        dataType: "json",
        url: "../../Ajax/TaskAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                var json = data.json;
                var tbody = "";
                var id = 0;
                var name = "";
                var pageCount = data.flag;
                $.each(json, function (k, v) {
                    if (k == 0) {
                        id = v.ID;
                        name = v.Name;
                        isReachCondition = v.IsReachCondition;
                    }
                    tbody += "<tr>"
                    tbody += "<td><a href='javascript:void(0)' onclick='javascript:GetPrizeAndConditionList(\"" + v.ID + "\",\"" + v.Name + "\",\"" + v.IsReachCondition + "\")'><lable name='lblName' id='" + v.ID + "'>";
                    tbody += v.Name;
                    tbody += "</label></a></td>";
                    tbody += "</tr>"
                })
                $("#tb1").empty().append(tbody);
                $("#pager").pager({ pagenumber: pageclickednumber, pagecount: Math.ceil(pageCount / pageSize), buttonClickCallback: PageClickFunc });
            }
        },
        complete: function () {
        },
        error: function () {
        }
    });

}
//查询下拉框选择方法
function InitSelectByType() {
    var sel = "";
    $.each(TaskTypeJsons, function (k, v) {
        if (k == 0) {
            sel += "<option value='" + v.ID + "' selected='selected'>" + v.Name + "</option>";
            InitPrizeList(v.ID)
        }
        else
            sel += "<option value='" + v.ID + "'>" + v.Name + "</option>";
    })
    return sel;
}

function GetPrizeAndConditionList(id, name, isCondition) {
    isReachCondition = isCondition;
    GetConditionList(id, name);
    GetPrizeList(id, name);
}

function DeletePrize(contr) {
    var id = $(contr).parent().parent().attr("id");
    if (window.confirm("确认删除？")) {
        $.ajax({
            type: "post",
            data: { action: "Delete", id: id },
            async: true,
            url: "../../Ajax/TaskPrizeAjax.ashx",
            beforeSend: function () {
            },
            success: function (data) {
                if (data == "True") {
                    $($(contr).parent().parent()).remove();
                    $.dialog.tips("删除成功！", 1);
                }
                else {
                    $.dialog.tips("删除失败！", 1);
                }
            },
            complete: function () {
            },
            error: function () {
            }
        })
    }
}

function AddPrizeMould(contr, sel) {
    var id = $(contr).parent().parent().attr("id");
    var taskID = $("#lblTaskID").attr("name");
    var prizeID = $("#selPrize").val();
    var prizeName = $(sel).find("option:selected").text()
    var isBest = $(sel).parent().parent().parent().find("input[name=radioIsBest]:checked").attr("value");
    var startCount = $("#txtStartCount").val() == undefined ? 0 : $("#txtStartCount").val();
    var endCount = $("#txtEndCount").val() == undefined ? 0 : $("#txtEndCount").val();
    var value = $("#txtValue").val();
    var data = null;
    if (isReachCondition == "True") {
        data = contr == null ? { action: "Add", prizeID: prizeID, taskID: taskID, value: value, isBest: isBest, startCount: 0, endCount: 0} :
              { action: "Update", id: id, prizeID: prizeID, taskID: taskID, value: value, isBest: isBest, startCount: 0, endCount: 0 };
    }
    else {
        data = contr == null ? { action: "Add", prizeID: prizeID, taskID: taskID, value: value, isBest: isBest, startCount: startCount, endCount: endCount} :
              { action: "Update", id: id, prizeID: prizeID, taskID: taskID, value: value, isBest: isBest, startCount: startCount, endCount: endCount };
    }
    $.ajax({
        type: "post",
        data: data,
        async: true,
        url: "../../Ajax/TaskPrizeAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                $.dialog.tips("更新成功！", 1);
                if (contr == null) {
                    var tbody = "";
                    tbody += "<tr id='" + data + "'>"
                    tbody += "<td><lable name='lblPrizeName' id='" + prizeID + "'>";
                    tbody += prizeName;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblValue'>";
                    tbody += value;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblStartCount'>";
                    tbody += startCount;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblEndCount'>";
                    tbody += endCount;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblIsBest'>";
                    tbody += isBest;
                    tbody += "</label></td>";
                    tbody += "<td>";
                    tbody += "<input type='button' onclick='UpdatePrize(this)' value='更新'><input type='button' onclick='DeletePrize(this)' value='删除'>";
                    tbody += "</td>";
                    tbody += "</tr>"
                    $("#tb3").append(tbody);
                }
                else {
                    $(contr).parent().parent().find("lable[name=lblPrizeName]").first().text(prizeName);
                    $(contr).parent().parent().find("lable[name=lblPrizeName]").first().attr("id", prizeID);
                    $(contr).parent().parent().find("lable[name=lblValue]").first().text(value);
                    $(contr).parent().parent().find("lable[name=lblStartCount]").first().text(startCount);
                    $(contr).parent().parent().find("lable[name=lblEndCount]").first().text(endCount);
                    $(contr).parent().parent().find("lable[name=lblIsBest]").first().text(isBest);
                }
            }
            else {
                $.dialog.tips("更新失败！", 1);
            }
        },
        complete: function () {
        },
        error: function () {
        }
    })
}

function UpdatePrize(contr) {
    EditPrize(contr);
}

function EditPrize(contr) {
    var prizeName = $(contr).parent().parent().find("lable[name=lblPrizeName]").first().text();
    var prizeID = $(contr).parent().parent().find("lable[name=lblPrizeName]").first().attr("id");
    var value = $(contr).parent().parent().find("lable[name=lblValue]").first().text();
    var isBest = $(contr).parent().parent().find("lable[name=lblIsBest]").first().text();
    var startCount = $(contr).parent().parent().find("lable[name=lblStartCount]").first().text();
    var endCount = $(contr).parent().parent().find("lable[name=lblEndCount]").first().text();
    var content = "";
    if (isReachCondition == "True") {
        if (contr != null) {
            content += "</br><table><tr><td>选择物品：<select id='selPrize'>" + InitSelectPrize(prizeID) + "</select></td></tr>";
            content += isBest == "True" ? "<tr><td>是否最高奖励：<input type='radio' name='radioIsBest' id='radioisTure' value='True' checked='checked' /><lable>是</lable><input type='radio' name='radioIsBest' id='radioisfalse' value='False'/><lable>否</lable></td></tr>"
                : "<tr><td>是否最高奖励：<input type='radio' name='radioIsBest' id='radioisTure' value='True'  /><lable>是</lable><input type='radio' name='radioIsBest' id='radioisfalse' value='False' checked='checked'/><lable>否</lable></td></tr>";
            content += "<tr><td>条件值：<input type='text' id='txtValue' value='" + value + "' style='width:200px' /></td></tr></table></br>";
        }
        else {
            content += "</br><table><tr><td>选择物品：<select id='selPrize'>" + InitSelectPrize() + "</select></td></tr>";
            content += "<tr><td>是否最高奖励：<input type='radio' name='radioIsBest' id='radioisTure' value='True' checked='checked' /><lable>是</lable><input type='radio' name='radioIsBest' id='radioisfalse' value='False'/><lable>否</lable></td></tr>";
            content += "<tr><td>条件值：<input type='text' id='txtValue' style='width:200px' /></td></tr></table></br>";
        }
    }
    else {
        if (contr != null) {
            content += "</br><table><tr><td>选择物品：<select id='selPrize'>" + InitSelectPrize(prizeID) + "</select></td></tr>";
            content += isBest == "True" ? "<tr><td>是否最高奖励：<input type='radio' name='radioIsBest' id='radioisTure' value='True' checked='checked' /><lable>是</lable><input type='radio' name='radioIsBest' id='radioisfalse' value='False'/><lable>否</lable></td></tr>"
                : "<tr><td>是否最高奖励：<input type='radio' name='radioIsBest' id='radioisTure' value='True'  /><lable>是</lable><input type='radio' name='radioIsBest' id='radioisfalse' value='False' checked='checked'/><lable>否</lable></td></tr>";
            content += "<tr><td>条件值：<input type='text' id='txtValue' value='" + value + "' style='width:200px' /></td></tr>";
            content += "<tr><td>开始名次：<input type='text' id='txtStartCount' value='" + startCount + "' style='width:200px' /></td></tr>"
            content += "<tr><td>结束名次：<input type='text' id='txtEndCount' value='" + endCount + "' style='width:200px' /></td></tr>"
            content += "</table></br>";
        }
        else {
            content += "</br><table><tr><td>选择物品：<select id='selPrize'>" + InitSelectPrize() + "</select></td></tr>";
            content += "<tr><td>是否最高奖励：<input type='radio' name='radioIsBest' id='radioisTure' value='True' checked='checked' /><lable>是</lable><input type='radio' name='radioIsBest' id='radioisfalse' value='False'/><lable>否</lable></td></tr>";
            content += "<tr><td>条件值：<input type='text' id='txtValue' style='width:200px' /></td></tr>";
            content += "<tr><td>开始名次：<input type='text' id='txtStartCount' style='width:200px' /></td></tr>"
            content += "<tr><td>结束名次：<input type='text' id='txtEndCount' style='width:200px' /></td></tr>"
            content += "</table></br>";
        }
    }
    $.dialog({
        title: "更新概率模板",
        content: content,
        button: [
                    {
                        name: "提交",
                        callback: function () {
                            AddPrizeMould(contr, $("#selPrize"));
                        }
                    },
                    {
                        name: "取消",
                        callback: function () {
                            this.close();
                        }
                    }
                    ],
        lock: true,
        drag: false

    });
}

function GetPrizeList(taskID, name) {
    $("#lblPrize").text(name);
    $("#lblPrize").attr("name", taskID)
    $.ajax({
        type: "post",
        data: { action: "GetList", taskID: taskID },
        dataType: "json",
        url: "../../Ajax/TaskPrizeAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                var json = data.json;
                var tbody = "";
                $.each(json, function (k, v) {
                    tbody += "<tr id='" + v.ID + "'>"
                    tbody += "<td><lable name='lblPrizeName' id='" + v.PrizeID + "'>";
                    tbody += v.PrizeName;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblValue'>";
                    tbody += v.PrizeCount;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblStartCount'>";
                    tbody += v.StartCount;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblEndCount'>";
                    tbody += v.EndCount;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblIsBest'>";
                    tbody += v.IsBest;
                    tbody += "</label></td>";
                    tbody += "<td>";
                    tbody += "<input type='button' onclick='UpdatePrize(this)' value='更新'><input type='button' onclick='DeletePrize(this)' value='删除'>";
                    tbody += "</td>";
                    tbody += "</tr>"
                })
                $("#tb3").empty().append(tbody);
            }
        },
        complete: function () {
        },
        error: function () {
        }
    });
}

function InitSelectPrize(value) {
    var sel = "";
    $.each(prizeJson, function (k, v) {
        if ((value == null && k == 0) || v.ID == value)
            sel += "<option value='" + v.ID + "' selected='selected'>" + v.Name + "</option>";
        else
            sel += "<option value='" + v.ID + "'>" + v.Name + "</option>";
    })
    return sel;
}

function InitSelectConditionMould(value) {
    var sel = "";
    $.each(mouldConditionJson, function (k, v) {
        if ((value == null && k == 0) || v.value == value)
            sel += "<option value='" + v.value + "' selected='selected'>" + v.name + "</option>";
        else
            sel += "<option value='" + v.value + "'>" + v.name + "</option>";
    })
    return sel;
}

function InitSelect(value) {
    var sel = "";
    if (isReachCondition != "True") {
        $.each(prizeJson, function (k, v) {
            if ((value == null && k == 0) || v.ID == value)
                sel += "<option value='" + v.ID + "' selected='selected'>" + v.Name + "</option>";
            else
                sel += "<option value='" + v.ID + "'>" + v.Name + "</option>";
        })
    }
    else {
        if (isMouldOrEvent == "False") {
            $.each(EventJson, function (k, v) {
                if ((value == null && k == 0) || v.ID == value)
                    sel += "<option value='" + v.ID + "' selected='selected'>" + v.Name + "</option>";
                else
                    sel += "<option value='" + v.ID + "'>" + v.Name + "</option>";
            })
        } else {
            $.each(mouldJson, function (k, v) {
                if ((value == null && k == 0) || v.ID == value)
                    sel += "<option value='" + v.ID + "' selected='selected'>" + v.MouldName + "</option>";
                else
                    sel += "<option value='" + v.ID + "'>" + v.MouldName + "</option>";
            })
        }
    }
    return sel;
}

function Delete(contr) {
    var id = $(contr).parent().parent().attr("id");
    if (window.confirm("确认删除？")) {
        $.ajax({
            type: "post",
            data: { action: "Delete", id: id },
            async: true,
            url: "../../Ajax/TaskConditionAjax.ashx",
            beforeSend: function () {
            },
            success: function (data) {
                if (data == "True") {
                    $($(contr).parent().parent()).remove();
                    $.dialog.tips("删除成功！", 1);
                }
                else {
                    $.dialog.tips("删除失败！", 1);
                }
            },
            complete: function () {
            },
            error: function () {
            }
        })
    }
}

function AddMould(contr, sel) {
    var id = $(contr).parent().parent().attr("id");
    var taskID = $("#lblTaskID").attr("name");
    var prizeID = $("#selPrize").val();
    var prizeName = $(sel).find("option:selected").text();
    var mouldConditionName = $("#selConditionMouldID").find("option:selected").text();
    var mouldConditionID = $("#selConditionMouldID").val();
    var value = $("#txtValue").val();

    var data = null;
    if (isReachCondition == "True") {
        if (isMouldOrEvent == "False")
            data = contr == null ? { action: "Add", prizeID: 0, ChanceMouldID: 0, EventID: prizeID, taskID: taskID, value: value, mouldConditionID: mouldConditionID} :
              { action: "Update", id: id, prizeID: 0, ChanceMouldID: 0, EventID: prizeID, taskID: taskID, value: value, mouldConditionID: mouldConditionID };
        else
            data = contr == null ? { action: "Add", prizeID: 0, ChanceMouldID: prizeID, EventID: 0, taskID: taskID, value: value, mouldConditionID: mouldConditionID} :
              { action: "Update", id: id, prizeID: 0, ChanceMouldID: prizeID, EventID: 0, taskID: taskID, value: value, mouldConditionID: mouldConditionID };
    }
    else {
        data = contr == null ? { action: "Add", prizeID: prizeID, ChanceMouldID: 0, EventID: 0, taskID: taskID, value: value, mouldConditionID: 0} :
              { action: "Update", id: id, prizeID: prizeID, ChanceMouldID: 0, EventID: 0, taskID: taskID, value: value, mouldConditionID: 0 };
    }
    $.ajax({
        type: "post",
        data: data,
        async: true,
        url: "../../Ajax/TaskConditionAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                $.dialog.tips("更新成功！", 1);
                if (contr == null) {
                    var tbody = "";
                    tbody += "<tr id='" + data + "'>"
                    tbody += "<td><lable name='lblPrizeName' id='" + prizeID + "'>";
                    tbody += prizeName;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblMouldConditionName' id='" + mouldConditionID + "'>";
                    tbody += mouldConditionName;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblValue'>";
                    tbody += value;
                    tbody += "</label></td>";
                    tbody += "<td>";
                    tbody += "<input type='button' onclick='Update(this)' value='更新'><input type='button' onclick='Delete(this)' value='删除'>";
                    tbody += "</td>";
                    tbody += "</tr>"
                    $("#tb2").append(tbody);
                }
                else {
                    $(contr).parent().parent().find("lable[name=lblPrizeName]").first().text(prizeName);
                    $(contr).parent().parent().find("lable[name=lblPrizeName]").first().attr("id", prizeID);
                    $(contr).parent().parent().find("lable[name=lblValue]").first().text(value);
                    $(contr).parent().parent().find("lable[name=lblMouldConditionName]").first().text(mouldConditionName);
                }
            }
            else {
                $.dialog.tips("更新失败！", 1);
            }
        },
        complete: function () {
        },
        error: function () {
        }
    })
}

function Update(contr, isMouldEvent) {
    isMouldOrEvent = isMouldEvent;
    Edit(contr);
}

function ChangeType() {
    if ($("#selMouldOrEvent").val() == "mould") {
        isMouldOrEvent = "True";
        var td = "选择模板：<select id='selPrize'>" + InitSelect() + "</select>";
        $("#tdSel").empty().append(td);
    }
    else {
        isMouldOrEvent = "False";
        var td = "选择事件：<select id='selPrize'>" + InitSelect() + "</select>";
        $("#tdSel").empty().append(td);
    }
}

function Edit(contr) {
    var prizeName = $(contr).parent().parent().find("lable[name=lblPrizeName]").first().text();
    var prizeID = $(contr).parent().parent().find("lable[name=lblPrizeName]").first().attr("id");
    var value = $(contr).parent().parent().find("lable[name=lblValue]").first().text();
    var mouldConditionID = $(contr).parent().parent().find("lable[name=lblMouldConditionName]").first().attr("id");
    var content = "";
    //任务达到条件即可兑换奖品
    if (isReachCondition == "True") {
        //事件条件选择
        if (isMouldOrEvent == "False") {
            content = "</br>选择条件类型：<select id='selMouldOrEvent' onchange='ChangeType()'><option value='mould'>模板</option><option value='event' selected='selected'>事件</option></select>";
            if (contr != null) {
                content += "<table><tr><td id='tdSel'>选择事件：<select id='selPrize'>" + InitSelect(prizeID) + "</select></td></tr>"
                content += "<tr><td>任务条件类型：<select id='selConditionMouldID'>" + InitSelectConditionMould(mouldConditionID) + "</select></td></tr>";
                content += "<tr><td>值：<input type='text' id='txtValue' value='" + value + "' style='width:200px' /></td></tr></table></br>";
            }
            else {
                content += "</br><table><tr><td id='tdSel'>选择事件：<select id='selPrize'>" + InitSelect() + "</select></td></tr>"
                content += "<tr><td>任务条件类型：<select id='selConditionMouldID'>" + InitSelectConditionMould() + "</select></td></tr>";
                content += "<tr><td>值：<input type='text' id='txtValue' style='width:200px' /></td></tr></table></br>";
            }

        } else {//模板条件选择
            content = "</br>选择条件类型：<select id='selMouldOrEvent' onchange='ChangeType()'><option value='mould' selected='selected'>模板</option><option value='event'>事件</option></select>";
            if (contr != null) {
                content += "<table><tr><td id='tdSel'>选择模板：<select id='selPrize'>" + InitSelect(prizeID) + "</select></td></tr>";
                content += "<tr><td>任务条件类型：<select id='selConditionMouldID'>" + InitSelectConditionMould(mouldConditionID) + "</select></td></tr>";
                content += "<tr><td>值：<input type='text' id='txtValue' value='" + value + "' style='width:200px' /></td></tr></table></br>";
            }
            else {
                content += "</br><table><tr><td id='tdSel'>选择模板：<select id='selPrize'>" + InitSelect() + "</select></td></tr>"
                content += "<tr><td>任务条件类型：<select id='selConditionMouldID'>" + InitSelectConditionMould() + "</select></td></tr>";
                content += "<tr><td>值：<input type='text' id='txtValue' style='width:200px' /></td></tr></table></br>";
            }
        }
    }
    //达到任务条件可参加此任务
    else {
        if (contr != null)
            content = "</br><table><tr><td id='tdSel'>选择物品：<select id='selPrize'>" + InitSelect(prizeID) + "</select></td></tr>"
                + "<tr><td>值：<input type='text' id='txtValue' value='" + value + "' style='width:200px' /></td></tr></table></br>";
        else
            content = "</br><table><tr><td id='tdSel'>选择物品：<select id='selPrize'>" + InitSelect() + "</select></td></tr>"
                + "<tr><td>值：<input type='text' id='txtValue' style='width:200px' /></td></tr></table></br>";
    }
    DiologShow(contr, content);
}

function DiologShow(contr, content) {
    $.dialog({
        title: "更新概率模板",
        content: content,
        button: [
                    {
                        name: "提交",
                        callback: function () {
                            AddMould(contr, $("#selPrize"));
                        }
                    },
                    {
                        name: "取消",
                        callback: function () {
                            this.close();
                        }
                    }
                    ],
        lock: true,
        drag: false
    });
}

function GetConditionList(taskID, name) {
    $("#lblTaskID").text(name);
    $("#lblTaskID").attr("name", taskID)
    $.ajax({
        type: "post",
        data: { action: "GetList", taskID: taskID },
        dataType: "json",
        url: "../../Ajax/TaskConditionAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                var json = data.json;
                var tbody = "";
                $.each(json, function (k, v) {
                    tbody += "<tr id='" + v.ID + "'>"
                    if (v.PrizeID != 0 && v.ChanceMouldID == 0 && v.EventID == 0) {
                        tbody += "<td><lable name='lblPrizeName' id='" + v.PrizeID + "'>";
                        tbody += v.PrizeName;
                        tbody += "</label></td>";
                    }
                    else if (v.PrizeID == 0 && v.ChanceMouldID != 0 && v.EventID == 0) {
                        tbody += "<td><lable name='lblPrizeName' id='" + v.ChanceMouldID + "'>";
                        tbody += v.ChanceMouldName;
                        tbody += "</label></td>";
                        isMouldOrEvent = "True";
                    }
                    else if (v.PrizeID == 0 && v.ChanceMouldID == 0 && v.EventID != 0) {
                        tbody += "<td><lable name='lblPrizeName' id='" + v.EventID + "'>";
                        tbody += v.EventName;
                        tbody += "</label></td>";
                        isMouldOrEvent = "False";
                    }
                    tbody += "<td><lable name='lblMouldConditionName' id='" + v.TaskMouldConditionID + "'>";
                    tbody += v.TaskMouldConditionName;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblValue'>";
                    tbody += v.ConditionValue;
                    tbody += "</label></td>";
                    tbody += "<td>";
                    if (v.PrizeID == 0 && v.ChanceMouldID != 0 && v.EventID == 0)
                        tbody += "<input type='button' onclick='Update(this,\"True\")' value='更新'><input type='button' onclick='Delete(this)' value='删除'>";
                    else if (v.PrizeID == 0 && v.ChanceMouldID == 0 && v.EventID != 0)
                        tbody += "<input type='button' onclick='Update(this,\"False\")' value='更新'><input type='button' onclick='Delete(this)' value='删除'>";
                    else
                        tbody += "<input type='button' onclick='Update(this)' value='更新'><input type='button' onclick='Delete(this)' value='删除'>";
                    tbody += "</td>";
                    tbody += "</tr>"
                })
                $("#tb2").empty().append(tbody);
            }
        },
        complete: function () {
        },
        error: function () {
        }
    });
}
